var ctx=window.daijia.ctx;
$(document).ready(function(){
	
//	var newDate = new Date();
//	var startDate = new Date();
//	startDate.setDate(startDate.getDate()-30);
//	var startTimeStr=startDate.getFullYear()+"-"+((startDate.getMonth()+1)>9?(startDate.getMonth()+1):'0' + (startDate.getMonth()+1))+"-"+(startDate.getDate()>9?startDate.getDate():'0' + startDate.getDate())+" "+"00:00";
//	var endTimeStr=newDate.getFullYear()+"-"+((newDate.getMonth()+1)>9?(newDate.getMonth()+1):'0' + (newDate.getMonth()+1))+"-"+(newDate.getDate()>9?newDate.getDate():'0' + newDate.getDate())+" "+"00:00";
//	$("#startTime").val(startTimeStr);
//	$("#endTime").val(endTimeStr);
	
	$("#startTime").datetimepicker({
        format: "yyyy-mm-dd HH:ii",
        language: 'zh-CN',
        showMeridian: true,
        autoclose: true,
        todayBtn: true
    });
	$("#endTime").datetimepicker({
		format: "yyyy-mm-dd HH:ii",
        language: 'zh-CN',
        showMeridian: true,
        autoclose: true,
        todayBtn: true
    });
	
	//点击搜索
	$("#search_button").click(function(){
		$("#SearchForm").submit();
	});
	
	//开始导出
	$("#export_button").click(function(){
		window.location=ctx+"/chart/exportCompany?startTime="+$("#startTime").val()+"&endTime="+$("#endTime").val();
	});
	
});

function loadData(){
	
	if($('#loadblacklayer').length==0){
		var dw = $(".table").width();
		var dh = $(".table").height();
		var backlayer ="<div id='loadblacklayer'><div style='margin-top:"+(dh/2)+"px;margin-left:"+(dw/2)+"px;'><img src='"+ctx+"/assets/css/images/loading.gif' /></div></div>"
		$(".table tbody").append(backlayer);
		$('#loadblacklayer').css({"z-index":"9","background":"#000","opacity":"0.5","position":'absolute',"top":0,"width":dw,"height":dh});
	}
	
	var	newcontent="";
	$.ajax({
        url : ctx+'/chart/companyOrderDate',
        type:'GET',
        async:true,
        dataType : 'json',
        data : {
        	"startTime":$("#startTime").val(),
        	"endTime":$("#endTime").val(),
        },
        success : function(result){
        	
        	if(result.length>0){
        	newcontent+="<tbody style='display:none;'>";	
        		$(result).each(function(index,data){
        	newcontent+="<tr>"+
						"<td>"+data.companyName+"</td>"+
						"<td>"+data.finishNums+"</td>"+
						"<td><span style='color:#ff950b;font-weight:700;'>"+data.money+"</span></td>"+
						"<td><span style='color:#ff950b;font-weight:700;'>"+data.cancelNums+"</span></td>"+
						"</tr>";
        		});
        	newcontent+="</tbody>";
        	}
        	$('#loadblacklayer').remove();
        	$(".table tbody").remove();
        	$(".table").append(newcontent);
        	$(".table tbody").show(300);
    		newTotalElements=result.length;
    		$(".pageshow").each(function(index,element){
			$(element).find("li a").html("共 "+newTotalElements+" 条数据");});
        }
	});
	
	//return newTotalElements;
	
	
	
	
}

function errandLoadData(){
	
	if($('#loadblacklayer').length==0){
		var dw = $(".table").width();
		var dh = $(".table").height();
		var backlayer ="<div id='loadblacklayer'><div style='margin-top:"+(dh/2)+"px;margin-left:"+(dw/2)+"px;'><img src='"+ctx+"/assets/css/images/loading.gif' /></div></div>"
		$(".table tbody").append(backlayer);
		$('#loadblacklayer').css({"z-index":"9","background":"#000","opacity":"0.5","position":'absolute',"top":0,"width":dw,"height":dh});
	}
	
	var	newcontent="";
	$.ajax({
        url : ctx+'/chart/errandCompanyOrderDate',
        type:'GET',
        async:true,
        dataType : 'json',
        data : {
        	"startTime":$("#startTime").val(),
        	"endTime":$("#endTime").val(),
        },
        success : function(result){
        	
        	if(result.content.length>0){
        	newcontent+="<tbody style='display:none;'>";	
        		$(result.content).each(function(index,data){
        	newcontent+="<tr>"+
						"<td>"+data.companyName+"</td>"+
						"<td>"+data.finishNums+"</td>"+
						"<td><span style='color:#ff950b;font-weight:700;'>"+data.money+"</span></td>"+
						"<td><span style='color:#ff950b;font-weight:700;'>"+data.cancelNums+"</span></td>"+
						"</tr>";
        		});
        	newcontent+="</tbody>";
        	}
        	$('#loadblacklayer').remove();
        	$(".table tbody").remove();
        	$(".table").append(newcontent);
        	$(".table tbody").show(300);
    		newTotalElements=result.length;
    		$(".pageshow").each(function(index,element){
			$(element).find("li a").html("共 "+newTotalElements+" 条数据");});
        }
	});
	
	//return newTotalElements;
	
	
	
	
}


	

